﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
////using System.Linq;
using System.Text;
using System.Windows.Forms;
using Zzva.Common;
using Zzva.DomainObject;
using Zzva.DomainObjectReg;



namespace Zzva.UIWin
{
    public partial class TFrmDirSoftware: TFrmDirBase 
    {
        private TDirSoftwareNew mvarDirSoftwareNew; 
        private int mvarId; //ИД корректируемого объета, если постоянный то = 0



        private void FrmRegDirSoftType_Ready(object Sender, EventArgs ArgsBase)
        {
            try
            {
                TDirEventArgs lDirEventArgs = (TDirEventArgs)ArgsBase;
                mvarDirSoftwareNew.SoftType = (TDirSoftTypeBase)lDirEventArgs.Dir;
                
                ////txtSoftType.Text = mvarDirSoftwareNew.SoftType.Obozn;
                txtSoftType.Text = mvarDirSoftwareNew.SoftType.ToString();

            }
            catch (Exception e) { MessageBox.Show(e.Message); }
            finally { }
        }

        private void DeleteSoftType()
        {
            TDirSoftTypeNull lDirSoftTypeNull = new TDirSoftTypeNull();
            mvarDirSoftwareNew.SoftType = lDirSoftTypeNull;
            
            ////txtSoftType.Text = mvarDirSoftwareNew.SoftType.Obozn;
            txtSoftType.Text = mvarDirSoftwareNew.SoftType.ToString();

        }

        private void FrmRegDirITCompany_Ready(object Sender, EventArgs ArgsBase)
        {
            try
            {
                TDirEventArgs lDirEventArgs = (TDirEventArgs)ArgsBase;
                mvarDirSoftwareNew.Developer = (TDirITCompanyBase)lDirEventArgs.Dir;
               
                ////txtDeveloper.Text = mvarDirSoftwareNew.Developer.Obozn;
                txtDeveloper.Text = mvarDirSoftwareNew.Developer.ToString();

            }
            catch (Exception e) { MessageBox.Show(e.Message); }
            finally { }
        }


        private void DeleteDeveloper()
        {
            TDirITCompanyNull lDirITCompanyNull = new TDirITCompanyNull();
            mvarDirSoftwareNew.Developer = lDirITCompanyNull;

            ////txtDeveloper.Text = mvarDirSoftwareNew.Developer.Obozn;
            txtDeveloper.Text = mvarDirSoftwareNew.Developer.ToString();

        }

        private void DeleteHolder()
        {
            TDirITCompanyNull lDirITCompanyNull = new TDirITCompanyNull();
            mvarDirSoftwareNew.Holder = lDirITCompanyNull;

            ////txtHolder.Text = mvarDirSoftwareNew.Holder.Obozn;
            txtHolder.Text = mvarDirSoftwareNew.Holder.ToString() ;

        }


        // создание нового объекта
        public TFrmDirSoftware(): base()
        {
            InitializeComponent();

            mvarDirSoftwareNew = new TDirSoftwareNew();
            mvarId = 0;

            txtObozn.Text = mvarDirSoftwareNew.Obozn;
            txtNaim.Text = mvarDirSoftwareNew.Naim;

            ////txtHolder.Text = mvarDirSoftwareNew.Holder.Obozn;
            txtHolder.Text = mvarDirSoftwareNew.Holder.ToString();

            ////txtDeveloper.Text = mvarDirSoftwareNew.Developer.Obozn;
            txtDeveloper.Text = mvarDirSoftwareNew.Developer.ToString();

            ////txtSoftType.Text = mvarDirSoftwareNew.SoftType.Obozn;
            txtSoftType.Text = mvarDirSoftwareNew.SoftType.ToString();


            mvarFlgChanch = false;

        }


        // создание нового объекта, на вход шаблон нового объекта
        public TFrmDirSoftware(TDirSoftwareNew pDirSoftwareNew): base()
        {
            InitializeComponent();

            mvarDirSoftwareNew = pDirSoftwareNew;
            mvarId = 0;

            txtObozn.Text = mvarDirSoftwareNew.Obozn;
            txtNaim.Text = mvarDirSoftwareNew.Naim;

            ////txtHolder.Text = mvarDirSoftwareNew.Holder.Obozn;
            txtHolder.Text = mvarDirSoftwareNew.Holder.ToString();

            ////txtDeveloper.Text = mvarDirSoftwareNew.Developer.Obozn;
            txtDeveloper.Text = mvarDirSoftwareNew.Developer.ToString();

            ////txtSoftType.Text = mvarDirSoftwareNew.SoftType.Obozn;
            txtSoftType.Text = mvarDirSoftwareNew.SoftType.ToString();

            mvarFlgChanch = false;
        }


        //на вход существующий объект
        public TFrmDirSoftware(TDirSoftware pDirSoftware): base()
        {
            InitializeComponent();

            mvarDirSoftwareNew = GetCopyDir(pDirSoftware);
            mvarId = pDirSoftware.Id;

            txtObozn.Text = mvarDirSoftwareNew.Obozn;
            txtNaim.Text = mvarDirSoftwareNew.Naim;


            ////txtHolder.Text = mvarDirSoftwareNew.Holder.Obozn;
            txtHolder.Text = mvarDirSoftwareNew.Holder.ToString() ;

            ////txtDeveloper.Text = mvarDirSoftwareNew.Developer.Obozn;
            txtDeveloper.Text = mvarDirSoftwareNew.Developer.ToString() ;

            ////txtSoftType.Text = mvarDirSoftwareNew.SoftType.Obozn;
            txtSoftType.Text = mvarDirSoftwareNew.SoftType.ToString() ;


            mvarFlgChanch = false;
        }



































































































        private void cmdDeleteSoftType_Click(object sender, EventArgs e)
        {
            DeleteSoftType();
        }






        private void txtSoftType_TextChanged(object sender, EventArgs e)
        {
            mvarFlgChanch = true;
        }

        private TDirSoftwareNew GetCopyDir(TDirSoftware pDirSoftware)
        {
            TDirSoftwareNew lDirSoftwareNew;
            string lObozn;
            string lNaim;
            TDirITCompanyBase lHolder;
            TDirITCompanyBase lDeveloper;

            ////
            TDirSoftTypeBase lSoftType; 


            lObozn = (string)pDirSoftware.GetAttrib("Obozn");
            lNaim = (string)pDirSoftware.GetAttrib("Naim");
            lHolder = (TDirITCompanyBase)pDirSoftware.GetAttrib("Holder");
            lDeveloper = (TDirITCompanyBase)pDirSoftware.GetAttrib("Developer");
            
            ////
            lSoftType = (TDirSoftTypeBase)pDirSoftware.GetAttrib("SoftType"); 
            
            
            lDirSoftwareNew = new TDirSoftwareNew(lObozn, lNaim);
            lDirSoftwareNew.Holder = lHolder;
            lDirSoftwareNew.Developer = lDeveloper;

            ////
            lDirSoftwareNew.SoftType = lSoftType;


            return lDirSoftwareNew;
        }










        private void cmdOpenFrmRegDirSoftType_Click(object sender, EventArgs e)
        {
            OpenFrmRegDirSoftType();
        }


        private void OpenFrmRegDirSoftType()
        {
            try
            {
                TFrmRegDirSoftType lFrmRegDirSoftType;
                TRegDirSoftType lRegDirSoftType;
                lRegDirSoftType = TRegDirSoftType.GetObject();
                lFrmRegDirSoftType = new TFrmRegDirSoftType(lRegDirSoftType);
                lFrmRegDirSoftType.EventReady += new EventHandler(FrmRegDirSoftType_Ready);
                lFrmRegDirSoftType.FindByDir((TDirBase)mvarDirSoftwareNew.SoftType);
                lFrmRegDirSoftType.ShowDialog();
            }

            catch (Exception e1) { MessageBox.Show(e1.Message); }
            finally { }
        }


 






















































































 










        private void cmdOpenFrmRegDirITCompany2_Click(object sender, EventArgs e)
        {
            OpenFrmRegDirITCompany();
        }

        private void OpenFrmRegDirITCompany()
        {
            try
            {
                TFrmRegDirITCompany lFrmRegDirITCompany;

                TRegDirITCompany lRegDirITCompany;
                lRegDirITCompany = TRegDirITCompany.GetObject();
                lFrmRegDirITCompany = new TFrmRegDirITCompany(lRegDirITCompany);
                lFrmRegDirITCompany.EventReady += new EventHandler(FrmRegDirITCompany_Ready);

                lFrmRegDirITCompany.FindByDir((TDirBase)mvarDirSoftwareNew.Developer);  

                ////lFrmRegDirITCompany.Show();
                lFrmRegDirITCompany.ShowDialog(); 
            }

            catch (Exception e1) { MessageBox.Show(e1.Message); }
            finally { }
        }



















































        protected override void Ready()
        {
            try
            {
                string lObozn = txtObozn.Text;
                string lNaim = txtNaim.Text;
                mvarDirSoftwareNew.Obozn = lObozn;
                mvarDirSoftwareNew.Naim = lNaim;
                TDirEventArgs lDirEventArgs;
                lDirEventArgs = new TDirEventArgs(mvarDirSoftwareNew, mvarId);
                FireEventReady(lDirEventArgs);
                this.Close();
            }
            catch (Exception e){MessageBox.Show(e.Message);}
            finally { }
        }

        private void txtHolder_TextChanged(object sender, EventArgs e)
        {
            mvarFlgChanch = true ;
        }

        private void txtDeveloper_TextChanged(object sender, EventArgs e)
        {
            mvarFlgChanch = true;
        }

        private void cmdDeleteHolder_Click(object sender, EventArgs e)
        {
            DeleteHolder();
        }



        private void cmdDeleteDeveloper_Click(object sender, EventArgs e)
        {
            DeleteDeveloper();
        }



        private void cmdOpenFrmRegDirITCompany_Click(object sender, EventArgs e)
        {

        }





  






    }
}
